package com.gome.wechat.program.service.queryservice.impl;

import com.gome.wechat.program.common.util.MyBeanUtil;
import com.gome.wechat.program.dto.GroupActivityDetailDto;
import com.gome.wechat.program.entity.GroupActivity;
import com.gome.wechat.program.entity.GroupActivityUser;
import com.gome.wechat.program.entity.GroupPicture;
import com.gome.wechat.program.entity.User;
import com.gome.wechat.program.service.GroupActivityService;
import com.gome.wechat.program.service.GroupActivityUserService;
import com.gome.wechat.program.service.GroupPictureService;
import com.gome.wechat.program.service.queryservice.GroupActivityQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liwei113 on 2017/11/3 0003.
 */
@Service
public class GroupActivityQueryServiceImpl implements GroupActivityQueryService {


    @Autowired
    GroupActivityService groupActivityService;

    @Autowired
    GroupActivityUserService groupActivityUserService;

    @Autowired
    GroupPictureService groupPictureService;


    @Override
    public GroupActivityDetailDto getDetail(Long id) {
        GroupActivity groupActivity =  groupActivityService.findById(id);
        GroupActivityDetailDto result = new GroupActivityDetailDto();
        MyBeanUtil.copyProperties(groupActivity,result);
        List<User> users = groupActivityUserService.findJoinUserPhotos(id);
        result.setJoiners(users==null?new ArrayList<User>():users);
        Long joinCount = groupActivityUserService.getJoinCount(id);
        result.setJoinerCount(joinCount==null?0:joinCount);
        List<GroupPicture> groupPictures = groupPictureService.findByGroupActivityId(id);
        List<String> urls = new ArrayList<>();
        for(GroupPicture temp: groupPictures){
            urls.add(temp.getUrl());
        }
        result.setPics(urls);
        return result;
    }
}
